package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.entity.TbTrialLabelEntity;
import com.huatai.manage.service.TbTrialLabelService;
import com.huatai.manage.utils.ComUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 标签管理;(TbLabelManage)表控制层
 *
 * @author luoxc
 * @since 2023-03-14 14:13:36
 */
@RestController
@RequestMapping("label")
@Api(value = "标签管理", tags = "标签管理")
public class TbTrialLabelController {

	@Autowired
	private TbTrialLabelService tbTrialLabelService;


	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.labelName",
		"pageQuery.data.labelType"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	public R pageList(@RequestBody PageQuery<TbTrialLabelEntity> pageQuery) {
		return R.data(this.tbTrialLabelService.pageList(pageQuery));
	}

	@GetMapping("list")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.tbTrialLabelService.list());
	}


	@PostMapping("getByLabelId")
	@ApiOperation(value = "通过标签id查询单条数据", notes = "通过标签id查询单条数据")
	public R getOne(@ApiParam(name = "labelId",value = "标签id", required = true) @RequestParam("labelId") String labelId) {
		return R.data(this.tbTrialLabelService.getByLabelId(labelId));
	}


	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@RequestBody @Valid TbTrialLabelEntity tbTrialLabelEntity) {
		return R.status(this.tbTrialLabelService.save(tbTrialLabelEntity.setLabelId(ComUtil.getUUID())));
	}


	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@RequestBody @Valid TbTrialLabelEntity tbTrialLabelEntity) {
		return R.status(this.tbTrialLabelService.update(tbTrialLabelEntity));
	}


	@PostMapping("removes")
	@ApiOperation(value = "删除数据", notes = "删除数据")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.status(this.tbTrialLabelService.removes(remove.getIds()));
	}
}

